//The MIT License (MIT)
//
//Copyright (c) 2018 dote
//
//Permission is hereby granted, free of charge, to any person obtaining a copy of
//this software and associated documentation files (the "Software"), to deal in
//the Software without restriction, including without limitation the rights to
//use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
//the Software, and to permit persons to whom the Software is furnished to do so,
//subject to the following conditions:
//
//The above copyright notice and this permission notice shall be included in all
//copies or substantial portions of the Software.
//
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
//FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
//COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
//IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
//CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

package com.github.dote.mio.client;

import com.github.dote.mio.client.callback.SendCallback;
import com.github.dote.mio.protocal.Packet;
import com.github.dote.mio.rtt.RTTHandler;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;

import java.util.Map;

public interface IOClient extends  Comparable<IOClient>{

    /**
     * 获取sid
     * @return
     */
    String getSessionId();

    /**
     * 获取ip
     * @return
     */
    String getIp();

    /**
     * 添加额外属性
     * @param k
     * @param v
     */
    void setAttr(String k,Object v);

    /**
     * 是否存在某个额外属性
     * @param k
     * @return
     */
    boolean hasAttr(String k);

    /**
     * 获取额外属性
     * @param k
     * @param <T>
     * @return
     */
    <T> T getAttr(String k,Class<T> clazz);

    <T> T getAttr(String k);

    /**
     * 获取所有额外属性
     * @return
     */
    Map<String,Object> getAttrMap();

    /**
     * 转发包
     * @param packet 包
     * @param toSessionId sid
     */
    void transfer(Packet packet,String toSessionId);

    /**
     * 转发包
     * @param packet 包
     * @param toSessionId sid
     * @param sendCallback 发送结果回调
     */
    void transfer(Packet packet,String toSessionId,SendCallback sendCallback);

    /**
     * 发送包
     * @param packet 包
     * @param sendCallback 发送结果回调
     */
    void send(Packet packet,SendCallback sendCallback);

    /**
     * 发送包
     * @param packet 包
     */
    void send(Packet packet);

    /**
     * 发送事件包
     * @param eventName 事件名称
     * @param fromSessionId 来自sid
     * @param data 事件名称对应得数据
     * @param ack 是否使用ack机制
     * @param sendCallback 发送结果回调
     */
    void send(String eventName,String fromSessionId,Object data,boolean ack,SendCallback sendCallback);

    /**
     * 发送事件包
     * @param eventName 事件名称
     * @param fromSessionId 来自sid
     * @param data 事件名称对应得数据
     * @param sendCallback 发送结果回调
     */
    void send(String eventName,String fromSessionId,Object data,SendCallback sendCallback);

    /**
     * 发送事件包
     * @param eventName 事件名称
     * @param fromSessionId 来自sid
     * @param data 事件名称对应得数据
     * @param ack 是否使用确认机制
     */
    void send(String eventName,String fromSessionId,Object data,boolean ack);

    /**
     * 使用确认机制发送事件包
     * @param eventName 事件名称
     * @param fromSessionId 来自sid
     * @param data 事件名称对应得数据
     */
    void send(String eventName,String fromSessionId,Object data);

    /**
     * 使用确认机制发送来自sid=0的事件包
     * @param eventName 事件名称
     * @param data 事件名称对应得数据
     */
    void send(String eventName,Object data);

    void setRTTHandler(RTTHandler rttHandler);

    RTTHandler getRTTHandler();

    boolean isConnected();

    boolean close();
}
